package com.itmate.chenshiguang.contreolle;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.itmate.chenshiguang.entity.member;
import com.itmate.chenshiguang.service.MenberUserService;
import com.itmate.chenshiguang.entity.family;



/**
 * Servlet implementation class DoLogin
 */
@WebServlet("/DoLogin")
public class DoLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoLogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String msg="";
		//1获取用户名和密码
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		//2判断接受数据是否成功
		member pu=new member();
		pu.setPassword(password);
		pu.setUsername(username);
		if(MenberUserService.isExist(pu)){
			//传参数 查询所有用户信息
			List<member> pulist = MenberUserService.selectAlluser();
			request.setAttribute("pulist", pulist);
			request.getRequestDispatcher("/WEB-INF/jsp/csg/text.jsp").forward(request, response);
		}else {
			msg="密码错误";
			request.setAttribute("msg", msg);
			request.getRequestDispatcher("/WEB-INF/jsp/csg/login.jsp").forward(request, response);
		}


			

		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
